import matplotlib.pyplot as plt


# 这两行代码解决 plt 中文显示的问题
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False

fig, ax = plt.subplots(figsize=(14, 11))
title = "derf daily score"
# title = histogram_dto.title
# time_list = ['2021-01-01', '2021-01-06', '2021-01-11', '2021-01-16', '2021-01-21', '2021-01-26',
#              '2021-02-01', '2021-02-06', '2021-02-11', '2021-02-16', '2021-02-21', '2021-02-26',
#              '2021-03-01', '2021-03-06', '2021-03-11', '2021-03-16', '2021-03-21', '2021-03-26']
time_list = ['01-01', '01-06', '01-11', '01-16', '01-21', '01-26',
             '02-01', '02-06', '02-11', '02-16', '02-21', '02-26',
             '03-01', '03-06', '03-11', '03-16', '03-21', '03-26']
# time_list = histogram_dto.time_list
# 数值范围正负1，保留两位小数
acc_score_list = [0.75, 0.32, -0.35, 0.16, 0.15, -0.01, 0.75, 0.32, -0.35, 0.06, 0.15, -0.88, 0.75, 0.32,
                  -0.35, 0.09, 0.15, -0.88]
# acc_score_list = histogram_dto.acc_score_list
plt.bar(time_list, acc_score_list, width=0.3, color="#4A5AED")
plt.title(title, color="#FFFFFF", size="20")
index = 0
for value in acc_score_list:
    if value != 0:
        if value > 0:
            plt.text(index - 0.25, value + 0.03, "%s" % value, va='center', color="#FFFFFF")
        else:
            plt.text(index - 0.35, value - 0.03, "%s" % value, va='center', color="#FFFFFF")
    # else:
    #     plt.text(index - 0.35, value, "%s" % value, va='center', color="#FFFFFF")
    else:
        plt.text(index - 0.35, value, "missing", va='center', color="#FFFFFF")
    index += 1

for xticklabel in ax.get_xticklabels():
    xticklabel.set_color("#FFFFFF")

for yticklabel in ax.get_yticklabels():
    yticklabel.set_color("#FFFFFF")

ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)

save_path = ""
image_name = "derf逐日_原数据_202001_202003_2.png"
plt.savefig(save_path + image_name, bbox_inches='tight', transparent=True, pad_inches=0, facecolor='#171F67')
plt.clf()
plt.close(fig)
